const webpack = require("webpack")
const path = require("path")
const { defineConfig } = require('@vue/cli-service')

function resolve(dir) {
  return path.join(__dirname, dir)
}
module.exports = defineConfig({
  transpileDependencies: true,
  configureWebpack: {
    resolve: {
      alias: {
        "@": resolve("src"),
      },
    },
    plugins: [
      new webpack.ProvidePlugin({ // 注册为全局变量
        'post': [path.resolve('src/lib/post.js'), 'default'],
        'app': [path.resolve('src/lib/app.js'), 'default'],
      }),
    ]
  },
  devServer: {
    proxy: { // 设置跨域
      '/api': {
        changeOrigin: true,  //开启代理:在本地会创建一个虚拟服务端，然后发送请求数据
        target: 'http://localhost:5000',  //这里是后端接口
        pathRewrite: {
          '/api': '' // 会将本地的 /api/list/goods 代理为：http://localhost:5000/list/goods
        }
      },
      '/uploadFile': { // 工程的接口以/api开头
        target: 'http://localhost:5000', // 被代理服务
        changeOrigin: true, // 改变源
      },
    }
  },
})
